package com.gx.utils;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import org.flowable.engine.history.HistoricProcessInstance;

import java.util.Map;

public class MessageUtils {


    public static String waitMessage(String taskId, String prdName, Map<String, Object> processVariables) {
        JSONObject startInfo = (JSONObject) processVariables.get("startInfo");
        String startUserName = startInfo.getString("startUserName");
        String msg = startUserName + "发起了【" + prdName + "】,请您尽快处理";
        JSONObject body = new JSONObject();
        body.put("msg", msg);
        if (CollUtil.isNotEmpty(processVariables)) {
            JSONObject config = new JSONObject();
            config.put("taskId", taskId);
            config.put("startInfo", processVariables.get("startInfo"));
            body.put("config", config);
        }
        return body.toJSONString();
    }

    public static String endMessage(String taskId, HistoricProcessInstance instance) {
        String msg = "你的【" + instance.getProcessDefinitionName() + "】已完结";
        JSONObject body = new JSONObject();
        body.put("msg", msg);
        Map<String, Object> processVariables = instance.getProcessVariables();
        if (CollUtil.isNotEmpty(processVariables)) {
            JSONObject config = new JSONObject();
            config.put("taskId", taskId);
            config.put("startInfo", processVariables.get("startInfo"));
            body.put("config", config);
        }
        return body.toJSONString();
    }


    public static String returnMessage(String assUser, String startUser, String common, String prcName) {
        return assUser + "对" + startUser + "的【" + prcName + "】给予退回!" + "意见为: " + common + "现需要你进行处理";
    }

    public static String updateMessage(String prcName, Map<String, Object> processVariables) {
        String msg = "你的【" + prcName + "】被退回,请修改后重新提交";
        JSONObject body = new JSONObject();
        body.put("msg", msg);
        if (CollUtil.isNotEmpty(processVariables)) {
            JSONObject config = new JSONObject();
            config.put("taskId", "");
            config.put("startInfo", processVariables.get("startInfo"));
            body.put("config", config);
        }
        return body.toJSONString();
    }

}
